#ifndef _WEBFORM_H_
#define _WEBFORM_H_

// System header
#include <FBase.h>
#include <FIO.h>
#include <FUi.h>
#include <FWeb.h>
#include <FSystem.h>
#include <FLocations.h>
#include <FUix.h>
#include <FSocial.h>
// Form header
#include "ChangeMapTypeForm.h"
#include "FindLocationForm.h"
#include "FindDirectionForm.h"
#include "FormManager.h"
#include "TrafficJamForm.h"

#include "../Utility/MyParserXml.h"

#include "TwitterLoginForm.h"

#include "../Utility/MyParserXml.h"
//#include "MediaPlayer.h"
#include "../Utility/HuongDanDuongDiBangGiongNoi.h"

#include "SearchPlaceForm.h"
#include "../Utility/Downloader.h"
#include "../Model/CurrentLocationService.h"
#include"CameraPreviewForm.h"
#include "GoogleBuzz/Googlebuzzform.h"
#include "WebController.h"
#include "../Utility/Downloader.h"
#include "ShowFindDirectionResultForm.h"
//namespace
using namespace Osp::Base;
using namespace Osp::Base::Collection;
using namespace Osp::Ui;
using namespace Osp::Ui::Controls;
using namespace Osp::System;
using namespace Osp::Graphics;
using namespace Osp::Web::Controls;
using namespace Osp::App;
using namespace Osp::Locations;
using namespace Osp::Uix;
using namespace Osp::Media;
using namespace Osp::Base::Runtime;

class WebForm: public Osp::Ui::Controls::Form,
		public Osp::Ui::IActionEventListener,
		public Osp::Ui::ITouchEventListener,
		public Osp::Uix::ISensorEventListener,
		public ITimerEventListener,
		public ICurrentLocationMember,
		public Osp::Web::Controls::ILoadingListener,
		public IDownloadFinishedListener {

	// Construction
public:
	WebForm(void);
	virtual ~WebForm(void);
	bool Initialize(void);

	const static RequestId REQUEST_FINDLOCATION = 1030;
	const static RequestId REQUEST_FINDIRECTION = 1031;
	const static RequestId REQUEST_CHANGEMAPTYPE = 1032;
	const static RequestId REQUEST_READRESULT = 1033;
	const static RequestId REQUEST_FINDMULTIPOINT = 1034;

	// Implementation
private:
	RequestId currentDownloadTask;

	//variant
	bool coTheoVetViTriHienTai;
	float latitude;
	float longitude;


	//la ban so

	SensorManager sensorManager;
	Image image;
	int degree;

	bool showCompass;
	//ID
	const static int ID_SOFTKEY_ZOOMIN = 1025;
	const static int ID_SOFTKEY_ZOOMOUT = 1026;
	const static int ID_OPTIONMENU_MAPTYPE = 1027;
	const static int ID_OPTIONMENU = 1028;
	const static int ID_OPTIONMENU_SOCIETY = 1099;
	const static int ID_OPTIONMENU_GOOGLEBUZZ = 1029;
	const static int ID_OPTIONMENU_FINDLOCATION = 1030;
	const static int ID_OPTIONMENU_FINDDIRECTION = 1031;
	const static int ID_OPTIONMENU_WEATHER = 1032;
	const static int ID_OPTIONMENU_VITRIYEUTHICH = 1035;
	const static int ID_OPTIONMENU_TIMVITRI = 1036;
	const static int ID_OPTIONMENU_KETXE = 1037;
	const static int ID_OPTIONMENU_COMPASS = 1038;
	const static int ID_OPTIONMENU_HIDECOMPASS = 1042;
	const static int ID_OPTIONMENU_SHOWCOMPASS = 1043;
	const static int ID_OPTIONMENU_TWITTERFORM = 1039;
	const static int ID_BUTTON_CURRENT_LOCATION = 1041;
	const static int ID_FINDDIRECTION_TWOPOINT = 1051;
	const static int ID_FINDDIRECTION_MULTIPOINT = 1052;
	static int FormId;

	const static int ID_OPTIONMENU_AUGMENTREALITY = 1040;

	//Vi tri yeu thich
	Osp::Base::String m_Lat;
	Osp::Base::String m_Lng;

	Timer *pTimer;
	CameraForm *__pStartForm;
	Bitmap *pBitmapLaBan;
	Label *pCompass;
	Osp::Web::Controls::Web* pWeb;

	Osp::Ui::Controls::OptionMenu *pOptionMenu;

	HuongDanDuongDiBangGiongNoi *pHuongDanBangGiongNoi;

	String m_startPoint;
	String m_endPoint;
	String m_transport;
	bool m_readResult;
public:
	void SetCurrentLocation();
	void SetFormId(int FormId) {
		this->FormId = FormId;
	}
	static int GetFormId() {
		return FormId;
	}
	virtual result OnInitializing(void);
	virtual result OnTerminating(void);
	virtual void
	OnActionPerformed(const Osp::Ui::Control& source, int actionId);
	virtual void OnUserEventReceivedN(RequestId requestId,
			Osp::Base::Collection::IList* pArgs);
	void OnTimerExpired(Timer& timer);
	// Map control function
public:
	void SetMapTypeId(int intMapTypeId);
	void TimKiemBanDo(IList *args);
	void FindDirection(IList *listArg);
	void FindMultiPoint(IList *listArg);
public:
	result CreateCurrentLocationButton();
	//touch
	Osp::Base::String getMyLat();
	Osp::Base::String getMyLng();

	virtual void OnTouchDoublePressed(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchFocusIn(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchFocusOut(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchLongPressed(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchMoved(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchPressed(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
	virtual void OnTouchReleased(const Osp::Ui::Control &source,
			const Osp::Graphics::Point &currentPosition,
			const Osp::Ui::TouchEventInfo &touchInfo);
public:
	void DatCacMarkerViTriYeuThichLenMap();
	void DatCacMakerTimKiemViTriLenMap(Osp::Base::Collection::ArrayList*);
public:
	void HienThiExpandList(FormManager*);
	void YeuCauKiemTraDangNhapTwitter(FormManager*);
	//La ban so
public:

	void
	OnDataReceived(SensorType sensorType, SensorData &sensorData, result r);
	void VeLaiLaBan();
	void XoayBitmap();
public:
	void layThongTin(Osp::Base::String pDiaDiem);
	void hienThiViTriKetXe(char* strPath);
	void themToaDo(double lat, double lng);

	result createCompassControl();

	//compass
	void RegisterCompass();
	void UnRegisterCompass();
public:

	void showResultSearchPlaceInMap(Osp::Base::String namePlace);
	void showResultSearchPlaceByPlceInMap(Osp::Base::String address,
			Osp::Base::String tieuChiSearch);
public:
	/*Hien thi vi tri ban be trong twitter vao ban do*/
	Osp::Base::Collection::ArrayList* ArrayQueryJavascriptAddMarker;

	void ShowLocationFriendInMap(Osp::Base::String location,
			Osp::Base::String statusText,
			Osp::Base::String timeUpdateStatusText, Osp::Base::String urlPhoto);
	void ShowLocationListFriendInMap(IList*pListFriend);
	void ShowMarkerInArrayList();
	virtual void LocationUpdate(float longitude, float latitude);

public:

	virtual bool OnHttpAuthenticationRequestedN(const Osp::Base::String& host,
			const Osp::Base::String& realm,
			const Osp::Web::Controls::AuthenticationChallenge& authentication);
	virtual void OnHttpAuthenticationCanceled();
	virtual void OnLoadingStarted(void);
	virtual void OnLoadingCanceled(void);
	virtual void OnLoadingErrorOccurred(
			Osp::Web::Controls::LoadingErrorType error,
			const Osp::Base::String &reason);
	virtual void OnLoadingCompleted();
	virtual void OnEstimatedProgress(int progress);
	virtual void OnPageTitleReceived(const Osp::Base::String& title);
	virtual bool OnLoadingRequested(const Osp::Base::String& url,
			Osp::Web::Controls::WebNavigationType type);
	virtual Osp::Web::Controls::DecisionPolicy OnWebDataReceived(
			const Osp::Base::String& mime,
			const Osp::Net::Http::HttpHeader& header);

	result CreateWebControl(void);
	void ThongBaoLoi(Osp::Base::String value) ;
public:
	/*Augment Reality*/
	result KhoiTaoCamera(Osp::Ui::Controls::Frame *pFrame);
public:
	void OnDownloadComplete(Osp::Base::String url, Osp::Base::String path);
	void OnDownloadFailed(Osp::Base::String url, Osp::Base::String path);
	void OnDataDownloadComplete(int statusCode, ByteBuffer *buffer);

private:
	bool isFirstStart;/*If it true , this is a first time when you use camera*/

	Osp::Ui::Orientation __targetOrientation;

};

#endif	//_WebForm_H_
